package redis.gambing;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Tuple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

import static redis.gambing.GambleFinalString.*;

/**
 * 打印赌徒信息
 */
public class PrintBolt extends BaseRichBolt {
    private static final Logger logger = LoggerFactory.getLogger(PrintBolt.class);

    @Override
    public void prepare(Map<String, Object> topoConf, TopologyContext context, OutputCollector collector) {
    }

    @Override
    public void execute(Tuple input) {
        String gamblerId = input.getStringByField(GAMBLER_ID);
        Long money = input.getLongByField(HASH_GAMBLER_1_MONEY);
        Short times = input.getShortByField(HASH_GAMBLER_2_TIMES);
        Long asserts = input.getLongByField(HASH_GAMBLER_3_ASSERTS);
//        boolean gambleResult = input.getBooleanByField(GAMBLE_RESULT);

//        logger.info("\t\t赌徒Id：{}，赌资：{}，参赌次数：{}，总资产：{}，本次赌博结果：{}。", gamblerId, money, times, asserts, gambleResult);
        logger.info("\t\t赌徒Id：{}，赌资：{}，参赌次数：{}，总资产：{}。", gamblerId, money, times, asserts);
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
    }
}
